// 智能锁列表
import debounce from "debounce";
import * as MSroomAPI from "../../api/interfaces/MSroom";
import { HttpHandler } from "../../api/handle/httpHandler";
import { AES_Encrypt } from "../../utils/crypto";
import loginToast from "@/components/loginToast/loginToast";

Page({
  data: {
    hotelList: [

    ],
    modalShow: false
  },
  onLoad() {

  },

  onShow() {
    this.modalShow = true;
    // wx.showLoading({ title: "" });
    this.getHotelList();
    if (wx.getStorageSync('token')) {
      this.getTokens()
    }
  },
  getTokens() {
    MSroomAPI.getToken().then(res => {
      if (res.code == 200) {
        wx.removeStorageSync("access_token"); // 清空当前用户保存的登录状态
        wx.setStorageSync("access_token", AES_Encrypt(res.result));
      }
    })
  },
  scan() {
    // 允许从相机和相册扫码
    wx.scanCode({
      success(res) {
        wx.navigateTo({
          url: '/' + res.path
        })
      }
    })
  },
  // 进入酒店详情
  toDetail(e) {
    wx.navigateTo({
      url: "../roomList/roomList",
      success: function (res) {
        // 通过eventChannel向被打开页面传送数据
        res.eventChannel.emit('hotelInfo', {
          item: e.currentTarget.dataset.query,
        })
      }
    })
  },
  /* TODO 处理用户错误日志, 用户可自行操作日志上传 */
  handleShowLog(...args: any) {
    console.log("操作日志:", ...args);
  },
  // 获取酒店列表
  getHotelList() {
    MSroomAPI.hotelPage().then(res => {
      if (res.result) {
        let demo = res.result.records
        demo.forEach(e => {
          e.cover = 'https://lyms.imsdx.net/lyms/' + e.cover.split(',')[0]
        });
        this.setData({ hotelList: demo });
      }
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    // this.modifyKeyList();
  },
  onReachBottom() {
    // this.modifyKeyList(this.data.currentPageNo + 1);
  },







})